package cn.itcast.mybatis.jdbc;

import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Properties;

import org.junit.Before;
import org.junit.Test;

import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource;

public class DemoHikariPool {
	
	HikariDataSource dataSource = null;
	
	@Before
	public void init() {
		//利用第三方数据库池加载数据库连接
		
		HikariConfig hikariCp = new HikariConfig("D:\\\\暑期作业与笔记\\\\camp\\\\code\\\\day30\\\\config\\\\HikariCP.properties");
		
		dataSource = new HikariDataSource(hikariCp);
	}
	
	@Test
	public void test() throws SQLException {
		
		Connection connection = dataSource.getConnection();
		
		//写sql语句
		String sql = "select * from student where sid = ?";
		
		//通过预处理语句，获取sql
		PreparedStatement preparedStatement = connection.prepareStatement(sql);
		
		//用预处理语句，设置参数
		preparedStatement.setInt(1, 3);
		
		//获得结果集
		ResultSet executeQuery = preparedStatement.executeQuery();
		
		//遍历结果集
		while(executeQuery.next()) {
			
			System.out.println(executeQuery.getString("sid")+" "+executeQuery.getString("name"));
		}
		
	}
}
